<?php
    class user_view_Controller extends controllerBase
    {
        public function process()
        {
            $this->aParams['iiD'] =$this->iId;
            $oDatabase = new database();
            $sfamilyname ='';
            $oDatabase = new database(); 
            core::checkSession();
            $uriUser = URL::getLink('profile/id/'.$this->iId);
            $queryuser ='PREFIX foaf: <http://xmlns.com/foaf/0.1/>
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>
            PREFIX bus: <'.URL::getLink('id/bussiness#').'>

            SELECT * 
            WHERE
            {
            ?uri rdf:type foaf:Person.
            ?uri foaf:familyName ?username.
            FILTER(?uri= "'.$uriUser.'").
            }';
            $aListuser= $oDatabase->loadQuery($queryuser);
            if(count($aListuser['result']['rows'])!=0)
            {   
                $sfamilyname=$aListuser['result']['rows'][0]['username'];
            }

            $querylistProduct = 'PREFIX foaf: <http://xmlns.com/foaf/0.1/>
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>
            PREFIX bus: <'.URL::getLink('id/bussiness#').'>

            SELECT * 
            WHERE
            {
            ?uri rdf:type bus:product.
            ?uri bus:name ?name.
            OPTIONAL {?uri bus:ownUser ?user.
            ?user foaf:familyName ?ownUser.}.
            ?uri bus:defaultImage ?image.
            ?uri bus:price ?price.
            ?uri bus:description ?description.
            FILTER(?ownUser = "'.$sfamilyname.'").
            }';
            $aListProducts = $oDatabase->loadQuery($querylistProduct);
            $aproducts = array();
            $this->aParams['notfound']='';
            if(count($aListProducts['result']['rows'])!=0)
            {   
                $aproducts=$aListProducts['result']['rows'];
            }
            else
            {
                $this->aParams['notfound']='PLEASE ADD PRODUCT';
            }
            $this->aParams['alistproducts'] = $aproducts;
        }
    }
?>
